package dao.impl;

import dao.OrderDetailDao;
import entity.Order_Detail;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import util.C3P0Util;

import java.sql.SQLException;
import java.util.List;

public class OrderDetailDaoImpl implements OrderDetailDao{
	
	//设计方法用于返回操作数据库的qr对象
	private QueryRunner getQueryRunner(){
		return new QueryRunner(C3P0Util.getDataSource());
	}

	@Override
	public List<Order_Detail> queryAllOrderDetailByOrderId(Integer orderId) {
		QueryRunner qr = this.getQueryRunner();
		String sql = "select * from order_detail where order_id = ?";
		List<Order_Detail> list = null;
		try {
			list = qr.query(sql, orderId,new BeanListHandler<Order_Detail>(Order_Detail.class));
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}

}
